<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../assets/css/base.css">
    <style>
        .box{
            border: 1px solid black;
            padding: 4px 30px;
            margin-bottom: 4px;
        }
    </style>
</head>
<body>
    <div id="app" class="box">
        <pre v-pre class="note">
        1. 嵌套组件 beforeMount 之前包含beforeMount 生命周期，**由页面定义顺序由上而下，由外而内进行执行**
        2. 当项目中所有的 beforeMount 生命周期函数执行完成，vue将以**元素定义的顺序有上而下，有内而外依次执行mounted 函数，根组件的mounted永远最后执行**
        3. 由上述两个结论可知，在组件化构成的vue结构中，所有的组件都beforeMount都将优先于mounted执行
            + 应用：中央事件总线的 事件绑定和触发的定义描述
                + beforeMount 优先于mounted 函数执行，所以可以在beforeMount  完成事件绑定，保证无论什么组件结构，事件绑定是先执行
                + mounted 中完成事件触发，保证在触发事件时，事件已经完成了绑定操作
        </pre>
        <h5>组件A</h5>
        <comp-b></comp-b>
        <comp-c></comp-c>
    </div>
    <script type="module">
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";

        const CompD = {
            template:`
                <div class='box'>
                    <h5>组件D</h5>
                </div>
            `,
            beforeMount () {
                console.log("===>beforeMount-D");
            },
            mounted () {
                console.log("===>mounted-D");
            },
        }
        const CompE = {
            template:`
                <div class='box'>
                    <h5>组件E</h5>
                </div>
            `,
            beforeMount () {
                console.log("===>beforeMount-E");
            },
            mounted () {
                console.log("===>mounted-E");
            },
        }
        const CompB = {
            components: { CompD,CompE },
            template:`
                <div class='box'>
                    <h5>组件B</h5>
                    <comp-d></comp-d>
                    <comp-e></comp-e>
                </div>
            `,
            beforeMount () {
                console.log("==>beforeMount-B");
            },
            mounted () {
                console.log("==>mounted-B");
            },
        }
        const CompC = {
            template:`
                <div class='box'>
                    <h5>组件C</h5>
                </div>`,
            beforeMount () {
                console.log("==>beforeMount-C");
            },
            mounted () {
                console.log("==>mounted-C");
            },
        }

        createApp({
            components: { CompB,CompC },
            beforeMount () {
                console.log("=>beforeMount-A");
            },
            mounted () {
                console.log("=>mounted-A");
            },
        }).mount("#app");
    </script>
</body>
</html>